int** generateMatrix(int n, int* returnSize, int** returnColumnSizes) {
    int **res = (int **)malloc(n * sizeof(int *)); // 分配行
    for (int i = 0; i < n; i++) {
        res[i] = (int *)malloc(n * sizeof(int)); // 分配列
    }

    int startx = 0, starty = 0;
    int loop = n / 2;
    int mid = n / 2;
    int count = 1;
    int offset = 1;
    int i, j;

    // 设置 returnSize 和 returnColumnSizes
    *returnSize = n;
    *returnColumnSizes = (int *)malloc(n * sizeof(int));
    for (int k = 0; k < n; k++) {
        (*returnColumnSizes)[k] = n;
    }

    while (loop--) {
        i = startx;
        j = starty;

        // 填充上行从左到右
        for (j; j < n - offset; j++) {
            res[i][j] = count++;
        }
        // 填充右列从上到下
        for (i; i < n - offset; i++) {
            res[i][j] = count++;
        }
        // 填充下行从右到左
        for (; j > starty; j--) {
            res[i][j] = count++;
        }
        // 填充左列从下到上
        for (; i > startx; i--) {
            res[i][j] = count++;
        }

        // 第二圈开始时，起始位置加1
        startx++;
        starty++;

        // offset 控制每一圈每一条边的遍历长度
        offset += 1;
    }

    // 如果n为奇数的话，需要单独给矩阵最中间的位置赋值
    if (n % 2) {
        res[mid][mid] = count;
    }

    return res;
}
